package com.yufubao.strat.config.impl;

import cn.dev33.satoken.stp.StpInterface;
import com.yufubao.service.service.management.authorization.MenuService;
import com.yufubao.service.service.management.authorization.RoleService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Component;

import java.util.List;

/**
 * 自定义权限加载接口实现类
 */
@Component// 保证此类被 SpringBoot 扫描，完成 Sa-Token 的自定义权限验证扩展
@RequiredArgsConstructor
public class StpInterfaceImpl implements StpInterface {

    private final MenuService menuService;
    private final RoleService roleService;


    /**
     * 返回一个账号所拥有的权限码集合 
     */
    @Override
    public List<String> getPermissionList(Object loginId, String loginType) {
        Long managerId = Long.valueOf(loginId.toString());
        //根据人员id查询权限信息
        List<String> perms = menuService.selectPermsByManagerId(managerId);
        return perms;
    }

    /**
     * 返回一个账号所拥有的角色标识集合 (权限与角色可分开校验)
     */
    @Override
    public List<String> getRoleList(Object loginId, String loginType) {
        Long managerId = Long.valueOf(loginId.toString());
        //根据人员id查询角色信息
        List<String> roleKeyList = roleService.selectRoleKeyByManagerId(managerId );
        return roleKeyList;
    }

}
